version: "3"

services:
  redis-{{ redis_role }}:
    image: "redis:{{ redis_docker_tag }}"
    container_name: "redis-{{ redis_port }}"
    restart: "always"
    network_mode: "host"
    environment:
      CONF_HASH: "{{ lookup('template', 'redis.conf.j2') | striptags | trim | hash('md5') }}"
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "{{ redis_deploy_path }}/{{ redis_role }}/redis.conf:/usr/local/etc/redis/redis.conf:ro"
      - "{{ redis_deploy_path }}/{{ redis_role }}/data:/data"
      - "{{ redis_deploy_path }}/{{ redis_role }}/redis-takeover.sh:/usr/local/bin/redis-takeover.sh"
    entrypoint:
      - "redis-server"
      - "/usr/local/etc/redis/redis.conf"
    healthcheck:
      test: ["CMD", "bash", "/usr/local/bin/redis-takeover.sh"]
      interval: 15s
      timeout: 10s
      retries: 3
